<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/7/12
 * Time: 14:56
 */

namespace app\common\model;

use think\Model;
use think\facade\Config;

class Order extends Model
{

    //订单金额
    public function price(){
        return $this->hasOne('OrderPrice', 'order_id', 'id')->bind([
            'order_price',
            'coupon_price',
            'pay_price'
        ]);
    }


    public function brand(){
        return $this->hasOne('BusBrand', 'id', 'brand_id')->bind([
            'brand_name'=>'name'
        ]);
    }

    public function beginCity(){
        return $this->hasOne('City', 'id', 'begin_city')->bind([
            'bc_name' => 'name',
        ]);
    }

    //到达城市
    public function endCity(){
        return $this->hasOne('City', 'id', 'end_city')->bind([
            'ec_name' => 'name',
        ]);
    }

    //商家信息
    public function userInfo(){
        return $this->hasOne('User', 'id', 'user_id')->bind([
            'b_name' => 'business_name',
        ]);
    }

    //投递车企情况
    public function deliveryInfo(){
        return $this->hasMany('Delivery', 'order_id', 'id');
    }

    //途径地方
    public function place(){
        return $this->hasMany('OrderPlace', 'order_id', 'id');
    }

    public function getSkdTimeAttr($value){
        return date('Y-m-d', $value);
    }

    public function getPayTimeAttr($value){
        return date('Y-m-d H:i', $value);
    }

    //订单状态
    public function getStatusAttr($value){
        $statusArr = Config::get('order_status');
        return $statusArr[$value];
    }

    //付款状态
    public function getPayStatusTextAttr($value,$data){
        $payStatusArr = ['未付款', '已付款'];
        return $payStatusArr[$data['pay_status']];
    }

    //获取签名图片
    public function signature(){
        return $this->hasOne('user_signature', 'id', 'signature_id')->bind('thumb');
    }

}